﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;
namespace GUI
{
    public partial class QuanLyDLThucDon : Form
    {
        public QuanLyDLThucDon()
        {
            InitializeComponent();
        }
        void loaddl()
        {
            LOAIMONBUS lmBUS = new LOAIMONBUS();
            DataTable tb = new DataTable();
            tb = lmBUS.LayDSLoaiMonDaXoa();
            dtgDLLM.DataSource = null;
            dtgDLLM.DataSource = tb;
            /////////
            THUCDONBUS tdBUS = new THUCDONBUS();
            DataTable ds = new DataTable();
            ds = tdBUS.LayDSThucDonDaXoa();
            dtgDLTD.DataSource = null;
            dtgDLTD.DataSource = ds;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            LOAIMONBUS lmBUS = new LOAIMONBUS();
            LOAIMONDTO lmDTO = new LOAIMONDTO();
            string tl = dtgDLLM.CurrentRow.Cells[0].Value.ToString();
            if (tl == "")
            {
                MessageBox.Show("ban chua chon loai mon", "canh bao", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            lmDTO.TenLoai = tl;
            int kq = lmBUS.PhucHoiLoaiMonDaXoa(lmDTO);
            if (kq > 0)
            {
                MessageBox.Show("phuc hoi thanh cong");
                loaddl();
            }
            else
            {
                MessageBox.Show("phuc hoi that bai");
            }
        }

        private void QuanLyDLThucDon_Load(object sender, EventArgs e)
        {
            loaddl();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            THUCDONBUS tdBUS = new THUCDONBUS();
            THUCDONDTO tdDTO = new THUCDONDTO();
            string tm = dtgDLTD.CurrentRow.Cells[0].Value.ToString();
            string dvt = dtgDLTD.CurrentRow.Cells[1].Value.ToString();
            if (tm == "" || dvt == "")
            {
                MessageBox.Show("ban chua chon mon", "canh bao", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            tdDTO.TenMon = tm;
            tdDTO.DVT = dvt;
            int kq = tdBUS.PhucHoiThucDonDaxoa(tdDTO);
            if (kq > 0)
            {
                MessageBox.Show("phuc hoi thanh cong");
                loaddl();
            }
            else
            {
                MessageBox.Show("phuc hoi that bai");
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            LOAIMONBUS lmBUS = new LOAIMONBUS();
            LOAIMONDTO lmDTO = new LOAIMONDTO();
            string tl = dtgDLLM.CurrentRow.Cells[0].Value.ToString();
            if (tl == "")
            {
                MessageBox.Show("ban chua chon loai mon", "canh bao", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            lmDTO.TenLoai = tl;
            int kq = lmBUS.XoaThatSuLoaiMon(lmDTO);
            if (kq > 0)
            {
                MessageBox.Show("xoa that su thanh cong");
                loaddl();
            }
            else
            {
                MessageBox.Show("xoa that su  that bai");
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            THUCDONBUS tdBUS = new THUCDONBUS();
            THUCDONDTO tdDTO = new THUCDONDTO();
            string tm = dtgDLTD.CurrentRow.Cells[0].Value.ToString();
            string dvt = dtgDLTD.CurrentRow.Cells[1].Value.ToString();
            if (tm == "" || dvt == "")
            {
                MessageBox.Show("ban chua chon mon", "canh bao", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            tdDTO.TenMon = tm;
            tdDTO.DVT = dvt;
            int kq = tdBUS.XoaThatSuThucDon(tdDTO);
            if (kq > 0)
            {
                MessageBox.Show("xoa that su  thanh cong");
                loaddl();
            }
            else
            {
                MessageBox.Show("xoa that su  that bai");
            }
        }
    }
}
